﻿using Snake.Core;
using Snake.Mapping;

namespace Snake.SQL.SQLNode
{
    /// <summary>
    /// 属性访问节点
    /// </summary>
    class PropertyAccess : IExprNode
    {
        public BracketedName Alias;//架构
        public PropertyMap PropertyMap;//属性map
        public IExprNode Parent;//父节点

        public void Render(SQLWriter writer)
        {
            var type = PropertyMap.Property.PropertyType;
            if (type == typeof(bool) && !(Parent is Relational))
            {
                writer.Append(Alias + PropertyMap.Column, SQLStrings.Equal, "1");  
            }
            else
            {
                writer.Append(Alias + PropertyMap.Column);    
            }            
        }

        public Precedence Precedence
        {
            get { return Precedence.Hightest; }
        }
    }
}